<?php

namespace App\Console;

use App\Models\Administrator;
use App\Models\Clue;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\Log;

class Kernel extends ConsoleKernel
{
    /**
     * Define the application's command schedule.
     *
     * @param \Illuminate\Console\Scheduling\Schedule $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')->hourly();
        if (admin_setting("dispatch_overflow_enable")) {
            $time = admin_setting("dispatch_overflow_time", '09:20');
            $schedule->call(function () {
                Log::debug('进行溢出分配');
                Clue::redispatchOverflowClue();
            })->dailyAt($time);

        }
        if (admin_setting("auto_offline")) {
            $time = admin_setting("auto_offline_time", '20:00');
            $schedule->call(function () {
                Log::debug('进行人员离线操作');
                Administrator::offlineAllUser();
            })->dailyAt($time);
        }
        if (admin_setting('enable_back_up')) {
            $schedule->command("backup:clean")->dailyAt("04:40");
            $schedule->command("backup:run --disable-notifications")->dailyAt("04:59");
        }

        if (env('TEST_TASK', false)) {
            $schedule->call(function () {
                Log::debug('测试 任务');
            })->everyMinute();
        }

        $schedule->call(function () {
            deleteCacheFiles();
        })->daily();
        $schedule->command('log:prune')->daily();

    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__ . '/Commands');

        require base_path('routes/console.php');
    }
}
